package com.example.administrator.yuejian23.Fragment;


import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.example.administrator.yuejian23.Bean.Club;
import com.example.administrator.yuejian23.Bean.ClubCourse;
import com.example.administrator.yuejian23.Bean.ClubInfo;
import com.example.administrator.yuejian23.Const;
import com.example.administrator.yuejian23.R;
import com.example.administrator.yuejian23.Retrofit.RetrofitService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * A simple {@link Fragment} subclass.
 */
public class ClubIntroFragment extends Fragment {


    private TextView Club_Info_Name;
    private TextView Club_Info_Tel;
    private TextView Club_Info_Address;
    private TextView Club_Info_Time;
    private Retrofit retrofit;
    private String Club_Id;
    private ClubInfo clubInfo;

    public ClubIntroFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view= inflater.inflate(R.layout.fragment_club_intro, container, false);


        Club_Info_Name= (TextView) view.findViewById(R.id.club_info_name);
        Club_Info_Tel= (TextView) view.findViewById(R.id.club_info_tel);
        Club_Info_Time= (TextView) view.findViewById(R.id.club_info_time);
        Club_Info_Address= (TextView) view.findViewById(R.id.club_info_address);


        Club_Id=getActivity().getIntent().getStringExtra("Club_Id");

        /////////////////////////
        Retrofit retrofit=new Retrofit.Builder()
                .baseUrl(Const.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
       RetrofitService service=retrofit.create(RetrofitService.class);
        retrofit2.Call<ClubInfo> call=service.clubInfo(Club_Id);
        call.enqueue(new Callback<ClubInfo>() {
            @Override
            public void onResponse(Call<ClubInfo> call, Response<ClubInfo> response) {
                clubInfo=response.body();
                Club_Info_Name.setText(clubInfo.getIntroduction());
                Club_Info_Tel.setText(clubInfo.getClub_tel());
                Club_Info_Time.setText(clubInfo.getOpen_time());
                Club_Info_Address.setText(clubInfo.getDistrict_name());

            }

            @Override
            public void onFailure(Call<ClubInfo> call, Throwable t) {

                Toast.makeText(getActivity(),"获取俱乐部信息失败",Toast.LENGTH_SHORT).show();
            }
        });

        return view;
    }

}
